package com.topisv.tms.utils.yto;

import java.util.List;

import net.ytoec.kernel.response.Response;
import net.ytoec.kernel.response.batchqueryresponse.BatchQueryResponse;
import net.ytoec.kernel.response.mailnoresponse.MailNoResponse;

import com.topisv.tms.entity.ExpressConfigure;
import com.topisv.tms.jms.vo.ConsignorMessage;
import com.topisv.tms.jms.vo.Ordeno;

public class YTOMailNo {

	/**
	 * 申领面单号
	 * @return
	 * @throws Exception
	 */
	public static MailNoResponse mailNoRequest(ExpressConfigure expressConfigure) throws Exception{
		try {
			String apiUrl=expressConfigure.getUrl();
			String customerCode=expressConfigure.getAccount();
			String clientId=expressConfigure.getAccount();
			String parternId=expressConfigure.getPassword();
			return YTOMailNoUtil.mailNoRequest(apiUrl, customerCode, clientId, parternId);
		} catch (Exception e) {
			throw e;
		}
	}
	
	/**
	 * 创建单个订单
	 * @param consignor
	 * @param shippedOrder
	 * @throws Exception
	 */
	public static Response createOrder(ConsignorMessage consignor,Ordeno ordeno) throws Exception{
		try {
			String apiUrl=YTOInitParams.getCreateOrderUrl();
			String customerCode=YTOInitParams.getCustomerId(ordeno.getWhcode());
			String clientId=YTOInitParams.getClientId(ordeno.getWhcode());
			String parternId=YTOInitParams.getParternId(ordeno.getWhcode());
			return YTOMailNoUtil.createOrder(apiUrl, customerCode, clientId, parternId, consignor, ordeno);
		} catch (Exception e) {
			throw e;
		}
	}
	
	/**
	 * 创建一批订单
	 * @param consignor
	 * @param shippedOrders
	 * @throws Exception
	 */
	public static Response createOrder(ConsignorMessage consignor, List<Ordeno> ordenos,String whcode) throws Exception{
		try {
			String apiUrl=YTOInitParams.getMailNoUrl();
			String customerCode=YTOInitParams.getCustomerId(whcode);
			String clientId=YTOInitParams.getClientId(whcode);
			String parternId=YTOInitParams.getParternId(whcode);
			return YTOMailNoUtil.createOrder(apiUrl, customerCode, clientId, parternId, consignor, ordenos);
		} catch (Exception e) {
			throw e;
		}
	}
	
	/**
	 * 取消订单
	 * @param txLogisticID
	 * @return
	 * @throws Exception
	 */
	public static Response cancelOrder(String txLogisticID,String whcode)throws Exception{
		try {
			String apiUrl=YTOInitParams.getMailNoUrl();
			String customerId=YTOInitParams.getCustomerId(whcode);
			String clientId=YTOInitParams.getClientId(whcode);
			String parternId=YTOInitParams.getParternId(whcode);
			return YTOMailNoUtil.cancelOrder(apiUrl, customerId, clientId, parternId, txLogisticID);
		} catch (Exception e) {
			throw e;
		}
	}
	
	/**
	 * 更新电子面单号
	 * @param mailNo
	 * @param txLogisticID
	 * @return
	 * @throws Exception
	 */
	public static Response updateMailNo(String mailNo,String txLogisticID,String whcode)throws Exception{
		try {
			String apiUrl=YTOInitParams.getMailNoUrl();
			String clientId=YTOInitParams.getClientId(whcode);
			String parternId=YTOInitParams.getParternId(whcode);
			return YTOMailNoUtil.updateMailNo(apiUrl, clientId, parternId, mailNo, txLogisticID);
		} catch (Exception e) {
			throw e;
		}
	}
	
	/**
	 * 废弃的方法
	 * 查询一批电子面单流转状态信息
	 * @param mailNos
	 * @return
	 * @throws Exception
	 */
	public static BatchQueryResponse orderFlowQuery(List<String> mailNos,String whcode)throws Exception{
		try {
			String apiUrl=YTOInitParams.getMailNoUrl();
			String clientId=YTOInitParams.getClientId(whcode);
			String parternId=YTOInitParams.getParternId(whcode);
			return YTOMailNoUtil.orderFlowQuery(apiUrl, clientId, parternId, mailNos);
		} catch (Exception e) {
			throw e;
		}
	}
	
	/**
	 * 废弃的方法
	 * 查询单个电子面单流转状态信息
	 * @param mailNo
	 * @return
	 * @throws Exception
	 */
	public static BatchQueryResponse orderFlowQuery(String mailNo,String whcode)throws Exception{
		try {
			String apiUrl=YTOInitParams.getMailNoUrl();
			String clientId=YTOInitParams.getClientId(whcode);
			String parternId=YTOInitParams.getParternId(whcode);
			return YTOMailNoUtil.orderFlowQuery(apiUrl, clientId, parternId, mailNo);
		} catch (Exception e) {
			throw e;
		}
	}
	
	/**
	 * 查询订单流转详情
	 * @param mailNo
	 * @return
	 * @throws Exception
	 */
	public static String newOrderFlowQuery(String mailNo)throws Exception{
		try {
			String queryOrderUrl=YTOInitParams.getQueryOrderUrl();
			String appKey=YTOInitParams.getAppKey();
			String secret=YTOInitParams.getSecret();
			String userId=YTOInitParams.getUserId();
			return YTOMailNoUtil.newOrderFlowQuery(queryOrderUrl, appKey, secret, userId, mailNo);
		} catch (Exception e) {
			throw e;
		}
	}
	
}
